<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>优惠券</title>
<link href="<%=path%>/favicon.ico" rel="shortcut icon">
<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/dataTables/css/jquery.dataTables.min.css"/>
<link href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css"
	rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/bootstrap-datetimepicker.min.css">
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-12 text-right">
			   <i class="fa fa-times" onclick="javascript:colseCouponModal()"></i>
			</div>
			
			<div class="tabs-container">
			    <ul class="nav nav-tabs">
					<li id="sysCoupon" class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">优惠券</a>
					</li>
					<li id="thirdPartyCoupon" class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">第三方优惠券</a>
					</li>
				</ul>
			
			    <div class="tab-content">
					<div id="tab-1" class="tab-pane active">
						<div class="panel-body">
							<div class="col-md-12" style="margin-top:15px">
						       <form action="" class="form-inline col-sm-6">
								    <div class="form-group">
								       <label>关键字</label>
								       <input class="form-control" id="keyWord" type="text" placeholder="输入关键字" maxlength="12" onblur="checkLength(this)">
								    </div>
								    <div class="form-group" style="margin-left: 15px;">
								        <button id="coupon_search"   type="button" class="btn btn-primary">搜索
					                    </button>
								    </div>
							   </form>
						    </div>
						    <div class="col-sm-12" style="margin-top:20px;">
				                <div class="ibox float-e-margins">
				                    <div class="table-responsive">
				                         <table class="table-striped table-bordered table-hover" id="mydataTable" style="width:100%;">
				                            <thead>
				                                <tr>
				                                    <th>选择</th>
				                                    <th>名称</th>
				                                    <th>金额</th>
				                                    <th>使用条件</th>
				                                    <th>有效期</th>
				                                </tr>
				                            </thead>
				                            <tbody>
				                               
				                            </tbody>
				                        </table>
				                    </div>                 
				                </div>
				            </div>
						</div>
					</div>
					
					<div id="tab-2" class="tab-pane">
						<div class="panel-body">
						   <div class="col-md-12" style="margin-top:15px">
							   <div class="form-group col-sm-5 text-left" id="data_5">
									<div class="input-daterange input-group" id="datepicker">
										<input id="starttime" type="text"
											class="input-sm form-control" name="start" readonly value="2017-11-29" style="background-color: white;"/>
										<span class="input-group-addon">到</span> <input id="endtime"
											type="text" class="input-sm form-control" name="end" readonly style="background-color: white;"
											value="2017-12-29" />
									</div>
								</div>
						       <form action="" class="form-inline col-sm-6">
								    <div class="form-group">
								       <label>关键字</label>
								       <input class="form-control" id="search" type="text" placeholder="输入关键字" maxlength="12" onblur="checkLength(this)">
								    </div>
								    <div class="form-group" style="margin-left: 15px;">
								        <button id="btnSearch"   type="button" class="btn btn-primary">搜索
					                    </button>
								    </div>
							   </form>
						    </div>
						    <div class="col-sm-12" style="margin-top:20px;">
				                <div class="ibox float-e-margins">
				                    <div class="table-responsive">
				                         <table class="table-striped table-bordered table-hover" id="thirdPartyCouponTable" style="width:100%;">
				                            <thead>
				                                <tr>
				                                    <th>选择</th>
				                                    <th>批次名</th>
				                                    <th>创建时间</th>
				                                    <th>导入总量</th>
				                                    <th>状态</th>
				                                    <th>发送渠道</th>
				                                    <th>统计</th>
				                                </tr>
				                            </thead>
				                            <tbody>
				                            </tbody>
				                        </table>
				                    </div>                 
				                </div>
				            </div>
						</div>
					</div>
				</div>
			</div>
		    <div class="col-md-12 text-center" style="width:100%;">
		        <div class="col-md-3"></div>
		        <button type="button" onclick="javascript:colseCouponModal();" class="col-md-2 btn btn-w-m btn-outline btn-primary">取消</button> 
		        <div class="col-md-2"></div>
			    <button type="button" onclick="javascript:determineCoupon();" class="col-md-2 btn btn-w-m btn-primary">确定</button> 
			    <div class="col-md-3"></div>
		    </div>
	    </div>			
	</div>
</div>
    
    <div class="modal inmodal fade" id="couponStatistics" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
               
            </div>
        </div>
    </div>
    
    <div class="modal inmodal fade  bg-white" id="couponNotEnough" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
              <div class="col-md-12" style="background-color:#ffffff">
               <div class="col-md-12 text-right" style="margin-top:10px;margin-right:10px">
			      <i class="fa fa-times" onclick="javascript:colsecouponNotEnough()"></i>
			   </div>
               <div class="col-md-12 text-center" style="width:100%;">
                   <h2>可用券数量小于当前目标人数</h2>
               </div>
               <div class="col-md-12" >
	                 <h3 class="col-md-1"></h3> <h3 class="col-md-5" id="customerNum">目标人数：64</h3> <h3 class="col-md-5" id="unUsedCouponNum">可用券量：36</h3><h3 class="col-md-1"></h3>
	            </div>
	            
	            <div class="col-md-12 text-center" style="margin-bottom:20px;width:100%"> 
		             <button onclick="javascript:intent();" class="btn btn-w-m btn-primary">去导入</button>
		        </div>
              </div>
            
               
            </div>
        </div>
    </div>
    
    

	<script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
	<script
		src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
	<script
		src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
	<script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
	<script type="text/javascript"
		src="<%=path%>/hplus/js/plugins/dataTables/jquery.dataTables.min.js"></script>
	<script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/dateUtils.js"></script>
    <script type="text/javascript" src="<%=path%>/js/createMenuTab.js"></script>

<script type="text/javascript">

$(document).on('ifChecked', '.select_one', function() { 
	$(".thirdPartyCheckbox").parent().removeClass("checked");
    	$(this).attr("checked","checked"); 
		$(this).parent().addClass("checked");
		couponIds.length=0;
		var couponName=$(this).attr('couponName');
		console.log(couponName);
		couponNameMap.set(this.id,couponName);
		couponIdsMap.set(this.id,this.id);
		thirdPartyCouponIds.length=0;
		thirdCouponNameMap.clear();
		console.log("-->"+thirdPartyCouponIdsMap);
		/* modelIds[this.id]=this.id; */
		couponIdsMap.forEach(function (element, index, array) {
		    // element: 指向当前元素的值
		    // index: 指向当前索引
		    // array: 指向Array对象本身
		    couponIds.push(element);
		});
		tempCouponModelType=0;
		console.log("couponIds--->"+couponIds);
});
$(document).on('ifUnchecked', '.select_one', function() { 
	$(this).removeAttr("checked","checked"); 
	$(this).parent().removeClass("checked");
	var couponName=$(this).attr('couponName');
	couponIds.length=0;
	couponIdsMap.delete(this.id);
	console.log(couponNameMap.delete(this.id));
	couponIdsMap.forEach(function (element, index, array) {
	    // element: 指向当前元素的值
	    // index: 指向当前索引
	    // array: 指向Array对象本身modelIds
		 couponIds.push(element);
	});
	tempCouponModelType=0;
	console.log("couponIds--->"+couponIds);
});



$(document).on('ifChecked', '.selectThirdCoupon', function() { 
	countCouponNum(this.id);
	$(".childCheckbox").parent().removeClass("checked");
	$(this).attr("checked","checked"); 
	$(this).parent().addClass("checked");
	var couponName=$(this).attr('couponName');
	thirdCouponNameMap.set(this.id,couponName);
	thirdPartyCouponIds.length=0;
	thirdPartyCouponIdsMap.set(this.id,this.id);
	couponIds.length=0;
	couponNameMap.clear();
	/* modelIds[this.id]=this.id; */
	thirdPartyCouponIdsMap.forEach(function (element, index, array) {
	    // element: 指向当前元素的值
	    // index: 指向当前索引
	    // array: 指向Array对象本身
	    thirdPartyCouponIds.push(element);
	});
	tempCouponModelType=1;
	console.log("thirdPartyCouponIds--->"+thirdPartyCouponIds);
});
$(document).on('ifUnchecked', '.selectThirdCoupon', function() { 
	$(this).removeAttr("checked","checked"); 
	$(this).parent().removeClass("checked");
	var couponName=$(this).attr('couponName');
	thirdPartyCouponIds.length=0;
	thirdPartyCouponIdsMap.delete(this.id);
	console.log(thirdCouponNameMap.delete(this.id));;
	thirdPartyCouponIdsMap.forEach(function (element, index, array) {
	    // element: 指向当前元素的值
	    // index: 指向当前索引
	    // array: 指向Array对象本身modelIds
		 thirdPartyCouponIds.push(element);
	});
	tempCouponModelType=1;
	console.log("thirdPartyCouponIds--->"+thirdPartyCouponIds);

});

$('#couponNotEnough').on('hidden.bs.modal', function () {
	if(!$('body').hasClass('modal-open')&& couponModalStatus){
    	$("#parentBody").addClass('modal-open');
	} 
	
})
//监听
$('#couponStatistics').on('hidden.bs.modal', function () {
	if(!$('body').hasClass('modal-open')&& couponModalStatus){
    	$("#parentBody").addClass('modal-open');
	} 
	
})
    
    
function intent(){
	colsecouponNotEnough();
	var url="<%=path%>"+"/view/coupon/main";
	menuPublic("电子券",url,134);
}
</script>

<script type="text/javascript">
$(function(){
	    var path = "<%=path%>";
	    var myDataTable;
	    var access_token=$.cookie('access_token');
	   	var cid=$.cookie('cid');
	   	var uid=$.cookie('uid');
	   	var keyWord="";
	   	var startTime="";
	   	var endTime="";
	    var name="";
	    var face_value="";
	    var ids="";
	    var thirdPartyCouponTable;
	    var startTime;
	    var endTime;
	    $.fn.dataTable.ext.errMode = 'none';
	    $(function(){
	    	if(tempCouponModelType==1){
	    		$('#thirdPartyCoupon').addClass("active");
	    		$('#tab-2').addClass("active");
	    		$('#sysCoupon').removeClass("active");
	    		$('#tab-1').removeClass("active");
	    	}else{
	    		$('#sysCoupon').addClass("active");
	    		$('#thirdPartyCoupon').removeClass("active");
	    		$('#tab-2').removeClass("active");
	    		$('#tab-1').addClass("active");
	    	}
	    	
	    	init();
	    	
	    });
	    
	    function init(){
	    	var myDate = new Date();
	    	//获取当前年
	    	var year=myDate.getFullYear();
	    	//获取当前月
	    	var month=myDate.getMonth()+1;
	    	var beforeMonth=myDate.getMonth();
	    	var beforeYear=year;
	    	//获取当前日
	    	var day=myDate.getDate(); 
	    	if(month>12){
	    		year=year+1;
	    		month=1;
	    	}
	    	if(beforeMonth==0){
	    		beforeMonth=12;
	    		beforeYear=beforeYear-1;
	    	}
	    	console.log(year+"-"+month+"-"+day);
	    	console.log(beforeYear+"-"+beforeMonth+"-"+day);
	    	
	    	console.log($("#starttime"));
	    	//document.getElementById("endtime").value = year+"-"+month+"-"+day; 
	    	$("#endtime").val(year+"-"+month+"-"+day);
	    	$("#endtime").attr("value",year+"-"+month+"-"+day);
	    	$("#starttime").attr("value",beforeYear+"-"+beforeMonth+"-"+day);
	    	$("#starttime").val(beforeYear+"-"+beforeMonth+"-"+day); 
	    	
	    	$("#starttime").datepicker("setDate",beforeYear+"-"+beforeMonth+"-"+day);
	    	$("#endtime").datepicker("setDate",year+"-"+month+"-"+day); 
	    	
	    	
	    	myDataTable = dataTable();
	    	thirdPartyCouponTable=thirdPartyCouponTable();
	    }
	    
	    function dataTable(){
	    	return $('#mydataTable').DataTable({
	    		processing: true,
	    		ordering: false,
	    		searching: false,
	    		info: true,
	    		autoWidth: true,
	    		lengthChange: false,
	    		"order": [[ 2, "desc" ]],
	    	    language: {
	    	    	emptyTable: '没有数据表',
	    	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
	    			infoEmpty: '没有数据',
	    			lengthMenu: '每页显示 _MENU_ 条记录',
	    			loadingRecords: '正在加载数据....',
	    			processing: '正在处理数据....',
	    			zeroRecords: '没有找到匹配的记录',
	    			paginate: {
	    				first: '首页',
	    				previous: '前页',
	    				next: '后页',
	    				last: '尾页'
	    			}
	    	    },
	    	    order: [[1,'desc']],
	    		pageLength: 5,
	    	    pagingType: 'full_numbers',
	    	    columnDefs: [{
	    			render: function(data, type, full) {
	    				var result="";
	    				
	    				if(IsCheck(data) && tempCouponModelType==0){
	    					result='<div class="checkbox i-checks"><label class="is_checkd select_one" couponId="'+data+'" couponName="'+full.name+'" id="'+data+'"><input checked="checked" class="childCheckbox" type="checkbox" couponName="'+full.name+'" id="'+data+'"></label></div>';

	    				}else{
	    					 result='<div class="checkbox i-checks"><label class="is_checkd select_one" couponId="'+data+'" couponName="'+full.name+'" id="'+data+'"><input  class="childCheckbox" type="checkbox" couponName="'+full.name+'" id="'+data+'"></label></div>';

	    				}
	                    return result;
	                },
	    			targets: 0
	    		},{
	    			render: function(data, type, full) {
	    				if(StringEmpty(data)){
	    					return (Number(data)/100)+"元";
	    				}else{
	    					return "";
	    				}
	                },
	    			targets: 2
	    		},{
	    			render: function(data, type, full) {
	    				var result="";
	    				if(data!="0"){
	    					result="满"+Number(data)/100+"元使用";
	    				}else{
	    					result="无";
	    				}
	    				return result;
	                },
	    			targets: 3
	    		},{
	    			render: function(data, type, full) {
	    				
	    				var result="";
	    				var validityPeriodType=full.validityPeriodType;
	    				if(validityPeriodType==0){
	    					if(StringEmpty(full.startTime) && StringEmpty(full.endTime)){
	    						result=formatDateTimeYMD(full.startTime)+"—"+formatDateTimeYMD(full.endTime);
	    					}
	    				}else if(validityPeriodType==1){
	    					result="优惠券发送后"+full.afterDay+"有效";
	    				}
	    				
	    				
	    				return result;
	                },
	    			targets: 4
	    		}],
	    	    columns: func_columns(),
	    	    serverSide: true,
	    	   
	    	    ajax: {
	    	    	contentType: 'application/json;charset=utf-8',
	    	    	type: 'POST',
	    	    	url: func_AjaxUrl(),
	    	    	data: function(d){
	    	    		d.keyWord=keyWord;
	    	    		d.status=1;
	    				return JSON.stringify(d);
	    			}
	    		}
	    	    ,
	    	    "initComplete": function(settings, json) {
	    	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
	    	      }
	    	}).on( 'draw', function () {
	    		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	    	} );
	    	
	    }
	    
	    
	    
	    
	    
	    function func_AjaxUrl(){
	    	return path+"/couponDefinedTemplate/ajaxCouponDefinedTemplatePageList";
	    }
	    /**
	     *	设置列名，对应后台
	     */
	    function func_columns(){
	    	var jsonArr = [
	    		{"data":"id"},
	    		{"data":"name"},
	    		{"data":"faceValue"},
	    		{"data":"limitPrice"},
	    		{"data":"endTime"},
	    	];
	    	return jsonArr;
	    }
	    
	    $('#coupon_search').on("click",function(){
	    	keyWord=$('#keyWord').val();
	    	startTime=$('#starttime').val();
	    	endTime=$('#endtime').val();
	        func_dataTableReload();
	    })
	    function func_dataTableReload(){
	    	myDataTable.ajax.reload(function(){
	    		/* $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
	    		$('input').iCheck('uncheck'); */
	    	});
	    }
	    
	    
		     
	     //判断是否被选中
	     function IsCheck(id){
	    	 var result=false;
	    	 if(tempCouponModelType==1){
	    		 for(var i in thirdPartyCouponIds){
		    		 if(thirdPartyCouponIds[i]==id){
		    			 result=true;
		    			 break; 
		    		 }
		    	 }
	    	 }else{
	    		 for(var i in couponIds){
		    		 if(couponIds[i]==id){
		    			 result=true;
		    			 break; 
		    		 }
		    	 }
	    	 }
	    	 console.log("tempCouponModelType--->"+tempCouponModelType);
	    	 console.log("id--->"+id);
	    	 console.log("couponModelType--->"+couponModelType);
	    	 console.log("thirdPartyCouponIds--->"+thirdPartyCouponIds);
	    	 console.log("couponIds--->"+couponIds);
	    	 console.log("result--->"+result);
	    	 return result;
	     }
	     
	     
	     function thirdPartyCouponTable(){
		    	return $('#thirdPartyCouponTable').DataTable({
		    		processing: true,
		    		ordering: false,
		    		searching: false,
		    		info: true,
		    		autoWidth: true,
		    		lengthChange: false,
		    		"order": [[ 2, "desc" ]],
		    	    language: {
		    	    	emptyTable: '<div id="content_empty"  class="form-group white-bg" style="text-align:center;padding:200px 0;margin:0;">   <p>暂无第三方券，<a onclick="javascript:intent();">去导入</a></p></div>',
		    	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
		    			infoEmpty: '没有数据',
		    			lengthMenu: '每页显示 _MENU_ 条记录',
		    			loadingRecords: '正在加载数据....',
		    			processing: '正在处理数据....',
		    			zeroRecords: '没有找到匹配的记录',
		    			paginate: {
		    				first: '首页',
		    				previous: '前页',
		    				next: '后页',
		    				last: '尾页'
		    			}
		    	    },
		    	    order: [[1,'desc']],
		    		pageLength: 5,
		    	    pagingType: 'full_numbers',
		    	    columnDefs: [{
		    			render: function(data, type, full) {
		    				var result="";
		    				if(IsCheck(data) && couponModelType==1){
		    					result='<div class="checkbox i-checks"><label class="is_checkd selectThirdCoupon" couponId="'+data+'" couponName="'+full.name+'" id="'+data+'"><input checked="checked" class="thirdPartyCheckbox" type="checkbox" couponName="'+full.name+'" id="'+data+'"></label></div>';

		    				}else{
		    					 result='<div class="checkbox i-checks"><label class="is_checkd selectThirdCoupon" couponId="'+data+'"  couponName="'+full.name+'" id="'+data+'"><input  class="thirdPartyCheckbox" type="checkbox" couponName="'+full.name+'" id="'+data+'"></label></div>';

		    				}
		                    return result;
		                },
		    			targets: 0
		    		},{
		    			render: function(data, type, full) {
		    				var result="";
		    				if(data == "1"){
		    					result="未派送";
		    				}else if(data=="2"){
		    					result="派送中";
		    				}else if(data=="3"){
		    					result="派送完毕";
		    				}
		    				return result;
		                },
		    			targets: 4
		    		},{
		    			render: function(data, type, full) {
		    				var result="";
		    				if(data != null){
		    					$.ajax({
		    						async: false,
		    						url: path+"/thirdpartyCoupon/ajaxThirdpartyCouponStatisticsDetail?modelId="+data,
		    						success: function(data){
		    							if(data.status == "200"){
		    								$.each(data.data,function(i,d){
		    									result += "<p>"+d.channelName+"："+d.name+"</p>";
		    								});
		    							}
		    						}
		    					});
		    				}
		    				return result;

		                },
		    			targets: 5
		    		},{
		    			render: function(data, type, full) {
		    				return formatDateTimeYMD(data);
		                },
		    			targets: 2
		    		},{
		    			render: function(data, type, full) {
		    				var requestUrl="<%=path%>/view/coupon/thirdPartyCouponStatistics?modelId="+data;
		                    var result = "";
		                    result += "<a id='"+data+"' style='color:#1ab394' data-toggle='modal' href='"+requestUrl+"' data-target='#couponStatistics'>统计</a>&nbsp;";
		                    return result;
		                },
		    			targets: 6
		    		}],
		    	    columns: third_func_columns(),
		    	    serverSide: true,
		    	   
		    	    ajax: {
		    	    	contentType: 'application/json;charset=utf-8',
		    	    	type: 'POST',
		    	    	url: thirdCouponFuncAjaxUrl(),
		    	    	data: function(d){
		    	    		d.extra_search = func_ajaxData2();
		    				return JSON.stringify(d);
		    			}
		    		}
		    	    ,
		    	    "initComplete": function(settings, json) {
		    	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
		    	      }
		    	}).on( 'draw', function () {
		    		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

		    	} );
		    	
		    }
	     
	     function func_ajaxData2() {
	    	    var jsonObject = new Object();
	    	    jsonObject.startTime = $("#starttime").val()+" 00:00:00";
	    	    jsonObject.endTime = $("#endtime").val()+" 23:59:59";
	    	    jsonObject.status=1;
	    	    var name = $.trim($("#search").val());
	    	    if(name != ""){
	    	    	jsonObject.nameLike = name;
	    	    }
	    	    return jsonObject;
	     }
	     
	     
	     
	     function thirdCouponFuncAjaxUrl(){
		    	return path+"/thirdpartyCouponModel/ajaxPageList";
		    }
		    /**
		     *	设置列名，对应后台
		     */
		    function third_func_columns(){
		    	var jsonArr = [
		    		{"data":"id"},
		    		{"data":"name"},
		    		{"data":"createTime"},
		    		{"data":"num"},
		    		{"data":"status"},
		    		{"data":"id"},
		    		{"data":"id"},
		    	];
		    	return jsonArr;
		    }
		    
		    $('#btnSearch').on("click",function(){
		    	keyWord=$('#search').val();
		    	startTime=$('#starttime').val();
		    	endTime=$('#endtime').val();
		    	
		    	console.log("startTime--->"+startTime);
		    	thirdCouponDataTableReload();
		    })
		    function thirdCouponDataTableReload(){
		    	thirdPartyCouponTable.ajax.reload(function(){
		    		/* $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
		    		$('input').iCheck('uncheck'); */
		    	});
		    }
});


function countCouponNum(modelId){
	var url="<%=path%>/thirdpartyCoupon/ajaxThirdpartyCouponStatistics";
  	$.post(url, {
			"modelId":modelId,
		}, function(data) {
			if (data.status == 200) {
				var couponNum=data.data.unusedNum;
				if(couponNum<customerNum){
					$('#unUsedCouponNum').html("可用券数量："+couponNum);
					$('#customerNum').html("目标人数："+customerNum);
					$('#couponNotEnough').modal("show");
				}
			} else if(data.message=="20028"){
				loginDialog();
			}else {
				errorDialog("获取数据失败",data.message);
			}
		});
}

function menuPublic(name,url,id){
    var modelName = "iframe"+id;
    var iframes = $("iframe[name^='iframe']", window.parent.document);	

    var olIframes = null;							
    for(var i = 0; i < iframes.length; i++) {
       if(modelName == iframes[i].name){
        	olIframes = iframes[i];		
        }
    }			
    if(olIframes == null){
	  	 //将所有选中的样式清空
	     $('.page-tabs-content', window.parent.document).html($('.page-tabs-content', window.parent.document).html().replace("active",""));
	  	 //为首部选项卡赋值
	  	 $('.page-tabs-content', window.parent.document).append('<a id="tab'+id+'" href="javascript:;" class="active J_menuTab" data-id="'+url+'">'+name+' <i class="fa fa-times-circle"></i></a>');
	  	 //将所有选项卡选项卡选中状态置为none，模糊匹配
	  	 $("iframe[name^='iframe']", window.parent.document).css('display','none');		
	  	 //动态增加选项卡iframe，并将选中状态设置为inline
	  	 $('#content-main', window.parent.document).append('<iframe class="J_iframe" name="iframe'+id+'" src="'+url+'" style="display: inline;" data-id="'+url+'" seamless="" width="100%" height="100%" frameborder="0"></iframe>'); 
    }else{
  	  	//将所有选中的样式清空
  	    $('.page-tabs-content', window.parent.document).html($('.page-tabs-content', window.parent.document).html().replace("active",""));
    	$("#tab"+id, window.parent.document).addClass("active");
  	  	//将所有选项卡选项卡选中状态置为none，模糊匹配
  	  	$("iframe[name^='iframe']", window.parent.document).css('display','none');		
  	    $("iframe[name='iframe"+id+"']", window.parent.document).css('display',' inline');
    }

}


</script> 


</body>
</html>